<?php
/*
 * Shop online & eStore
 *
 * Author: mr.Trieu
 * Created: 22-11-2011
 * $shop.php
 *
 * */

define('APPTYPEID', 9);
define('CURSCRIPT', 'shop');

if (!empty($_GET['mod']))
	define('ALLOWGUEST', 1);

global $_G, $metakeywords, $metadescription;

require './source/class/class_core.php';
require './source/function/function_shop.php';

$discuz = & discuz_core::instance();

$modarray = array(
		'ajax',
		'index',
		'post',
		'view',
		'store',
		'list',
		'listprofile',
		'tags',
		'search'
);

$modcachelist = array(
		'index'=>array(
				'bbcodes_display',
				'bbcodes'
		),
		'post'=>array(
				'bbcodes_display',
				'bbcodes',
				'smileycodes',
				'smilies',
				'smileytypes',
				'domainwhitelist',
				'post'
		),
		'view'=>array(
				'bbcodes_display',
				'bbcodes',
				'smileycodes',
				'smilies',
				'smileytypes',
				'domainwhitelist',
				'view'
		),
		'list'=>array(
				'domainwhitelist',
				'bbcodes_display'
		)
);

$mod = !in_array($discuz->var['mod'], $modarray) ? 'index' : $discuz->var['mod'];
//echo $mod; exit();
define('CURMODULE', $mod);

$cachelist = array();

if (isset($modcachelist[CURMODULE]))
	$cachelist = $modcachelist[CURMODULE];

$discuz->cachelist = $cachelist;
$discuz->init();

/*
 * Tam ngung de nang cap
 * */
//if ($_G['adminid'] != 1){
//	showmessage('cho_woo_tam_ngung_de_nang_cap');
//}
/***********************************************/

loadshop();

// function like
require libfile('class/like');
// shopping cart
require libfile('class/cart');

// Quy dinh so luong san pham hien thi tren moi trang
$item_per_page = 16;

require libfile('function/shoplist');

// For Top Menu
$catHot = category_hot();
$subcategory_hot = subcategory_hot();

if (!$_G['gp_inajax']){
	$navigation = $navtitle = '';
	periodscheck('postbanperiods');
//	$navtitle = lang('shop/core','title_' . $_G['gp_action'] . '_post');

	loadcache('shops');

	if ($_G['sid']){
		$navigation = '<li class="first"><a href="/" title="{lang homepage}" style="z-index:9;"><span></span>' . $_G[setting][bbname] . '</a></li>';
	}
//	$navigation = '<li class="first"><a href="/" title="' . $_G['setting']['navs'][132]['navname'] . '" style="z-index:9;"><span></span>&nbsp;' . $_G['setting']['navs'][132]['navname'] . '</a></li>';

	if ($_G['shop']['type'] == 'sub'){
		$sup = $_G['cache']['shops'][$_G['shop']['sup']]['sup'];
		$t_link = $_G['cache']['shops'][$sup]['type'] == 'group' ? 'shop.php?name=' . locdau(strip_tags($_G['cache']['shops'][$sup]['name'])) . '&sid=' . $sup : '#';
		$navigation .= '<li><a href="' . $t_link . '" style="z-index:8;">' . strip_tags($_G['cache']['shops'][$sup]['name']) . '</a></li>';
	}

	if ($_G['shop']['sup']){
		$sup = $_G['shop']['sup'];
		$t_link = $_G['cache']['shops'][$sup]['type'] == 'group' ? 'shop.php?name=' . locdau(strip_tags($_G['cache']['shops'][$sup]['name'])) . '&sid=' . $sup : 'shop.php?name=' . locdau(strip_tags($_G['cache']['shops'][$sup]['name'])) . '&sid=' . $sup;
		$navigation .= '<li><a href="' . $t_link . '" style="z-index:7;">' . strip_tags($_G['cache']['shops'][$sup]['name']) . '</a></li>';
	}

	if ($_G['sid']){
		$t_link = 'shop.php?name=' . locdau(strip_tags($_G['shop']['name'])) . '&sid=' . $_G['sid'];
		$navigation .= '<li><a href="' . $t_link . '" style="z-index:6;">&nbsp;' . strip_tags($_G['shop']['name']) . '</a></li>';
	}

	if ($mod == 'post' && !$_G['gp_sid']){
		$navigation = '<li class="first"><a href="/" style="z-index:9;"><span></span>' . $_G['setting']['navs'][129]['navname'] . '</a></li><li><a href="shop.php?mod=post&action=newproduct" style="z-index:8;">' . lang('shop/template', 'post_product') . '</a></li>';
	}
}

$name = addslashes($_G['gp_name']);

$location_country = provice();

/*
 * Check total itemts in cart
 * return int number
 * */
$totalitemts = cart::totalitemts();

/*****************************************************************/
require DISCUZ_ROOT . './source/module/shop/shop_' . $mod . '.php';
